package com.xinnet.mms.listener;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class ApplicationTimer {
	
	private static Date currentDate;

	public synchronized static Date getCurrentDate() {
		if(currentDate==null){
			currentDate = new Date();
			return currentDate;
		}else{
			int currentMinute = currentDate.getMinutes();
			
			int tempMinute = new Date().getMinutes();
			
			if(tempMinute-currentMinute>3){
				Calendar begin=Calendar.getInstance();
				begin.setTime(currentDate);
				begin.add(Calendar.DATE,1);
				currentDate = begin.getTime();
				return currentDate;	
			}else{
				return currentDate;	
			}
		}
	}



	
	
	public static void main(String[] args) throws InterruptedException {
		currentDate = new Date();
		ApplicationTimer.getCurrentDate();
		SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		String dateStr =  df.format(currentDate);
		int a = currentDate.getMinutes();
		System.out.println("a: "+ a);
		Thread.sleep(200000);
		int b = new Date().getMinutes();
		System.out.println("b: "+ b);
	}
}
